import request from '@/utils/request'
/**
 *获取员工简单列表
 * @returns Promise
 */
export const getEmployeeList = () => {
  return request({
    method: 'get',
    url: '/sys/user/simple'
  })
}
/**
 * 获取员工列表
 * @returns
 */
export const getEmployeeDetailList = (page = 1, size = 10) => {
  return request({
    method: 'get',
    url: '/sys/user',
    params: {
      page,
      size
    }
  })
}
/**
 * 删除员工
 * @param {*} id 员工id
 * @returns
 */
export const delEmployee = (id) => {
  return request({
    method: 'delete',
    url: '/sys/user/' + id
  })
}
/**
 * 新增员工
 * @param {*} data
 * @returns
 */
export const addEmployee = (data) => {
  return request({
    method: 'post',
    url: '/sys/user',
    data
  })
}
/**
 * 批量导入员工 excel
 * @returns
 */
export const uploadEmployeeExcel = (data) => {
  return request({
    method: 'post',
    url: '/sys/user/batch',
    data
  })
}
/**
 * 获取员工基本信息
 * @param {*} id 员工id
 * @returns
 */
export const getEmployeeInfo = (id) => {
  return request({
    method: 'get',
    url: `/sys/user/${id}`
  })
}
/**
 * 保存/更新员工基本信息
 * @param {*} data
 * @returns
 */
export const updateEmployeeInfo = (data) => {
  return request({
    method: 'put',
    url: '/sys/user/' + data.id,
    data
  })
}
/** *
 *  读取员工详情的基础信息
 * **/
export function getPersonalDetail(id) {
  return request({
    method: 'get',
    url: `/employees/${id}/personalInfo`
  })
}

/** *
 *  更新员工详情的基础信息
 * **/
export function updatePersonal(data) {
  return request({
    url: `/employees/${data.userId}/personalInfo`,
    method: 'put',
    data
  })
}
/** **
 * 获取员工的岗位信息
 *
 * ****/
export function getJobDetail(id) {
  return request({
    url: `/employees/${id}/jobs`
  })
}

/**
 * 保存员工岗位信息
 * ****/
export function updateJob(data) {
  return request({
    url: `/employees/${data.userId}/jobs`,
    method: 'put',
    data
  })
}
/**
 * 给员工分配角色
 * @param {*} id 员工id
 * @param {*} roleIds 员工角色id列表
 * @returns
 */
export const assignRoles = (id, roleIds) => {
  return request({
    method: 'put',
    url: '/sys/user/assignRoles',
    data: {
      id,
      roleIds
    }
  })
}
